import washList from '../washList.vue' //洗车列表
import nearStoreList from '../near_store.vue' //店铺列表
// import welfareList from '../near_store.vue' //养车福利购
export default {
	components: {
		washList,
		nearStoreList,
		// welfareList
	},
	props: ['specifAll'],
	data() {
		return {
			showPage: false,
			storeTotal: 0, //门店总条数
			token: '',
			mycarlist: [], //我的爱车列表
			list: [],
			/* list: {
			  month: [], // 月
			  second: [], // 次
			  minute: [], // 分钟
			  recharge: [], // 计费
			  speed: [],//自动
			  standard: [],//标准
			  delicate: [],//精致
			  speedMonth: []
			}, //福利购列表 */
			bannerCurrent: 0, //banner当前

			storeList: [], //门店列表

			bannerswiperCurrent2: 0, //banner滑块
			//首页banner
			banners: [{
				path: '/pages_commodity/selfWash/selfWash',
				id: 0,
				img: 'https://files.yzsheng.com/client/index/banner/banner1.png'
			}],
			/* banners: [{
			  path: '/pages_common/pages_me/invitation/invitation',
			  id: 0,
			  img: 'https://files.yzsheng.com/client/index/banner/index1.jpg'
			},
			{
			  path: '/pages_buy_index/welfareDetails/welfareDetails',
			  id: 1,
			  img: 'https://files.yzsheng.com/client/index/banner/index3.jpg'
			}
			], */
			// icon
			// /pages_commodity/intelligence/intelligence //智能保养
			typeMenu: [{
					path: '/pages_commodity/selfWash/selfWash?index=0',
					imgSrc: 'zhizhuxiche',
					text: '自助洗车',
					id: 0,
				},
				{
					path: '/pages_commodity/selfWash/selfWash?index=1',
					imgSrc: 'zhidongxiche',
					text: '自动洗车',
					id: 1,
				},
				{
					path: '/pages_commodity/selfWash/selfWash?index=2',
					imgSrc: 'daixi',
					text: '代洗',
					id: 2,
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=0',
					imgSrc: 'newxiche',
					text: '门店洗车',
					id: 3,
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=1',
					imgSrc: 'neishi',
					text: '美容',
					id: 4,
				},
			],
			typeMenu2: [{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=2',
					imgSrc: 'iconxiaobaoyang',
					text: '小保养'
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=3',
					imgSrc: 'newbaoyang',
					text: '大保养'
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=7',
					imgSrc: 'newkuntai',
					text: '轮胎换修'
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance?index=8',
					imgSrc: 'newjiance',
					text: '车辆检测'
				},
				{
					path: '/pages_commodity/doMaintenance/doMaintenance',
					imgSrc: 'icongengduo2',
					text: '更多'
				},
			],
			headerHight: 0,

		}
	},
	created() {
		// this.getBuyDiscountsList()
		this.getCardList()
		this.getMaintainStoreList()
		this.token = uni.getStorageSync('token')
		if (this.token) {
			this.GetCarList()
		}
	},
	//#ifdef MP-WEIXIN
	options: {
		styleIsolation: 'shared'
	},
	//#endif
	methods: {
		//获取会员卡列表
		async getCardList() {
			uni.showLoading()
			try {
				let data = {
					'pageIndex': 1,
					'pageSize': 40,
					'cardType': 2
				}
				const res = await this.$api.selfServiceCarWash.getSelfServiceCarWashCardByTypeList(data)
				if (res.code === 200) {
					let list = res.data.list
					list.map(item => {
						if (item.card_Type === 1) {
							this.list.push(item)
							// console.log(item)
						}
					})

					// this.cardList = result
				}
				this.pageLoading = true
				uni.hideLoading()
			} catch (e) {
				uni.hideLoading()
			}
		},
		getHight() {
			//获取导航栏高度
			this.$nextTick(() => {
				const query = uni.createSelectorQuery().in(this)
				query.select('.car').boundingClientRect(data => {
					this.headerHight = data.height
					// console.log(this.headerHight,'car')
				}).exec()
			})

		},
		//判断智能保养是否登录再跳转
		goLink(url, id) {
			let token = uni.getStorageSync('token')
			if (!token) {
				this.$u.toast('请登录！')
				this.$u.debounce(this.login, 1000)
			} else {
				uni.navigateTo({
					url: url
				})
			}

		},
		goBanner(url, id) {
			let token = uni.getStorageSync('token')
			if (!token && id === 0) {
				this.$u.toast('请登录！')
				this.$u.debounce(this.login, 1000)
			} else {
				uni.navigateTo({
					url: url
				})
			}
		},
		//跳转登录
		login() {
			uni.setStorage({
				key: 'launchFlag',
				data: false,
			})
			uni.navigateTo({
				url: '/pages_logins/login/login'
			})
		},
		//我的爱车列表
		async GetCarList() {
			const value = uni.getStorageSync('Ztc_C_USER_INFO')
			if (value) {
				var ids
				ids = value.id
			}
			try {
				let data = {
					pageIndex: 1,
					pageSize: 1,
					uid: ids
				}
				const res = await this.$api.commodity.GetCarList(data)
				this.mycarlist = res.data.list.slice(0, 1)
				this.$nextTick(() => {
					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
					this.$emit('success', this.headerHight)
				})
			} catch (e) {
				this.$nextTick(() => {
					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
				})
			}
		},
		//我添加爱车
		async AddCar() {
			const value = uni.getStorageSync('Ztc_C_USER_INFO')
			if (value) {
				var ids
				ids = value.id
			}
			try {
				//添加爱车重复，退出添加
				this.mycarlist.forEach((item, index) => {
					if (item.car_Id === this.specifAll.Configulist.id) {

						// uni.showToast({
						//   title: '添加重复，请重新选择',
						//   icon: 'none'
						// })
						throw new Error('EndIterative')
					}
				})
				let data = {
					uid: ids,
					brand_Id: this.specifAll.brandlist.bid,
					brand_Name: this.specifAll.brandlist.brand,
					car_Type_Id: this.specifAll.Serieslist.carTypeId,
					car_Type_Name: this.specifAll.Serieslist.carTypeName,
					car_Id: this.specifAll.Configulist.id,
					car_Name: this.specifAll.Configulist.name,
					car_Num: this.specifAll.licenseplate, //车牌号
					mileage: 0, //里程 /km
					vin: '', //vin号
					engine: '', //发动机号
					displacement: this.specifAll.Displacement.pName,
					yeartype: this.specifAll.Modelyear.years
				}
				const res = await this.$api.common.AddCar(data)
				this.mycarlist = res.data.list
				this.GetCarList()
			} catch (e) {
				if (e.message !== 'EndIterative') throw e
			}
		},
		//添加配置
		addConf() {
			let token = uni.getStorageSync('token')
			if (!token) {
				this.$u.toast('请登录！')
				this.$u.debounce(this.login, 1000)
			} else {
				uni.navigateTo({
					url: '/pages_common/addYourCar/addYourCar?type=120' + '&pageFrom=carMaintenances'
				})
			}

		},

		//获取福利购列表
		async getBuyDiscountsList() {
			try {
				let data = {
					'pageIndex': 1,
					'pageSize': 1
				}
				const res = await this.$api.maintenanceIndex.getBuyDiscountsList(data)
				uni.stopPullDownRefresh()
				this.list = res.data.list
				this.showPage = true
				this.$nextTick(() => {

					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
					this.$emit('success', this.headerHight)
				})
			} catch (e) {
				this.$nextTick(() => {
					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
				})
			}
		},
		//跳转爱车详情
		goBy(index) {
			uni.navigateTo({
				url: '/pages_commodity/mylovecarInformation/mylovecarInformation?index=0' + '&current=1'
			})
		},
		//门店
		async getMaintainStoreList() {
			let lon = this.$store.state.lon
			let lat = this.$store.state.lat
			let code = Number(this.$store.state.postalCode)
			// let a = {a: lon,b: lat,c: code}
			// console.log(a)
			try {
				let data = {
					'pageIndex': 1,
					'pageSize': 2,
					'dlon': lon || 0,
					'dlat': lat || 0,
					'districtid': 0
				}
				// 30.567323
				// 104.063578
				const res = await this.$api.store.GetMaintainStoreList(data)
				uni.stopPullDownRefresh()
				this.storeTotal = res.data.total
				this.storeList = res.data.list
				this.showPage = true
				this.$nextTick(() => {

					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
					this.$emit('success', this.headerHight)
				})
			} catch (e) {
				uni.stopPullDownRefresh()
				this.$nextTick(() => {
					//#ifndef MP-WEIXIN
					this.getHight()
					//#endif
				})
			}
		},
		// 监听banner滑动 ??
		swiperChange(e) {
			this.bannerswiperCurrent2 = e.detail.current
		},
	}
}
